package homework.day01;

import java.io.File;
import java.io.FileFilter;
import java.util.Scanner;

/**
 * @Classname: HomeWork03
 * @Author: bromide
 * @CreateTime: 2022/3/29--10:33
 * @Version: V1.0
 * @Desciption: 程序启动后要求用户输入一个关键字，然后列出当前项目下所有
 * 名字中包含该关键字的子项
 */
public class HomeWork03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入需要查找的关键字：");
        String key = scanner.nextLine();
        File dir = new File("./");
        if (dir.isDirectory()) {
            File[] subs = dir.listFiles(file -> file.getName().contains(key));
            if (subs.length == 0) {
                System.out.println("未找到文件");
            } else {
                System.out.println("查找到以下文件：");
                for (int i = 0; i < subs.length; i++) {
                    System.out.println(subs[i].getName());
                }
            }
        }
    }
}
